package com.twu.biblioteca.model.item.movies;

import com.twu.biblioteca.model.item.Item;
import com.twu.biblioteca.model.item.ItemFormatter;
import com.twu.biblioteca.model.item.ItemID;
import com.twu.biblioteca.model.item.ItemStatus;

/**
 * Created with IntelliJ IDEA.
 * User: cschlumb
 * Date: 09/08/2013
 * Time: 10:09
 * To change this template use File | Settings | File Templates.
 */
public class MovieFormatter extends ItemFormatter{

    private final StringBuilder stringBuilder;

    public MovieFormatter() {
        stringBuilder = new StringBuilder();
    }

    private void add(ItemID id, Movie movie, ItemStatus status) {
        stringBuilder.append("ID: ");
        stringBuilder.append(id.getId());
        stringBuilder.append('\t');
        stringBuilder.append("Title: ");
        stringBuilder.append(movie.getTitle());
        stringBuilder.append('\t');
        stringBuilder.append("Year: ");
        stringBuilder.append(movie.getYear());
        stringBuilder.append('\t');
        stringBuilder.append("Director: ");
        stringBuilder.append(movie.getDirector());
        stringBuilder.append('\t');
        stringBuilder.append("Rating: ");

       Rating rating = movie.getRating();

       if (rating.isRated()){
           for (int i=0; i<rating.getRating(); i++)
               stringBuilder.append('*');
       }  else {
           stringBuilder.append("N/A");
       }

        if (status.equals(ItemStatus.RESERVED)){
            stringBuilder.append("\t(RESERVED)");
        }

        stringBuilder.append("\n");
    }

    @Override
    public void add(ItemID id, Item item, ItemStatus status) {
        add(id, (Movie) item, status);
    }

    @Override
    public String toFormattedString(){
        return stringBuilder.toString();
    }
}
